﻿using RapChieuPhim.BUS;
using RapChieuPhim.DTO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace RapChieuPhim.DAO
{
    class CTPhongChieuDAO
    {
        public IList GetAll(int phim)
        {
            DataProvider cn = new DataProvider();
            ArrayList array = new ArrayList();
            DataTable dt = cn.SqlExcuteQuery("LayPhongChieuTheoPhim");

            if (dt.Rows.Count != 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    CTPhongChieuDTO CTPC = new CTPhongChieuDTO();
                    CTPC.Phongchieu = PhongChieuBUS.GetByID(int.Parse(dr["MaPhong"].ToString()));
                    CTPC.Phim = PhimBUS.GetByID(int.Parse(dr["MaPhim"].ToString()));
                    array.Add(CTPC);
                }
            }
            return array;
        }

        public void Insert(CTPhongChieuDTO CTPC)
        {
            DataProvider cn = new DataProvider();
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@MaPhong", CTPC.Phongchieu);
            param[1] = new SqlParameter("@MaPhim", CTPC.Phim);
            cn.SqlExcuteNonQuery("InsertCTPhongChieu", param);
        }

        public void Delete(int maphong, int phim)
        {
            DataProvider cn = new DataProvider();
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@MaPhong", maphong);
            param[1] = new SqlParameter("@MaPhim", phim);
            cn.SqlExcuteNonQuery("DeleteCTPhongChieu", param);
        }
    }
}
